<!-- 指标配置-查看页 -->
<template>
  <view class="s-list">
    <Header title="查看" bgColor="#fff" :leftIconSize="20"/>
    <view class='s-list-main'>
      <view class='s-box'>
        <view class="s-box-item">
          <view class="left">指标名称</view>
          <view class="right">{{ formData.name }}</view>
        </view>
        <view class="s-box-item">
          <view class="left">指标类型</view>
          <view class="right">
            <span v-if="formData.entryType === '1'">食品安全检查指标</span>
            <span v-else-if="formData.entryType === '2'">校园安全检查指标</span>
            <span v-else-if="formData.entryType === '3'">食堂自查指标</span>
            <span v-else-if="formData.entryType === '4'">校园自查指标</span>
            <span v-else-if="formData.entryType === '5'">配餐单位自查指标</span>
            <span v-else-if="formData.entryType === '6'">配餐单位食品安全检查指标</span>
            <span v-else-if="formData.entryType === '7'">学校有害生物防治检查指标</span>
            <span v-else-if="formData.entryType === '8'">学校有害生物防治自查指标</span>
          </view>
        </view>
        <view class="s-box-item">
          <view class="left">更新时间</view>
          <view class="right">{{ proxy.dayjs(formData.updateDate).format('YYYY-MM-DD') }}</view>
        </view>
      </view>
      <view class='s-list-main s-box s-check-main'>
        <view class='s-all-check'>
          <view class="num">序号</view>
          <view class="name">检查项目及内容</view>
          <view class="s-check"></view>
        </view>
        <view class='s-check-bottom'>
          <daTree ref="DaTreeRef" :data="treeData" labelField="content" valueField="id" expandChecked
                  :defaultCheckedKeys="defaultCheckedKeysValue" :showControl="false"/>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
  import entryAPI from "@/api/law/entry/entry";
  import targetEntryAPI from '@/api/law/target/targetEntry';
  import {deepClone} from './data';
  import {onLoad} from '@dcloudio/uni-app';
  import {ref, reactive, getCurrentInstance, defineProps, computed} from 'vue';

  const {proxy} = getCurrentInstance();
  const props = defineProps({
    row: {
      type: Object,
      default: () => {
        return {};
      }
    }
  });

  let formData = ref({});
  const entryList = ref([]);
  let userInfo = ref(uni.getStorageSync('userInfo'));
  let queryForm = reactive({
    entryType: '',
    createOrgId: userInfo.value.user.orgId,
    params: {
      ids: [],
    }
  });

  /** 数据加载 */
  onLoad((e) => {
    if (e.row) {
      formData.value = JSON.parse(decodeURIComponent(e.row))
      getTargetEntryList();
    }
  });

  /** 获取指标检查项关联列表 */
  let getTargetEntryList = async () => {
    let res = await proxy.http.asyncPost(targetEntryAPI.targetEntryPage, {targetId: formData.value.id});
    if (res.code === 0) {
      queryForm.params.ids = res.data.records.map(item => item.entryId);
      await getEntryList();
    } else {
      await uni.showToast({title: res.msg, icon: 'none'});
    }
  };

  /** 获取检查项列表 */
  let getEntryList = async () => {
    queryForm.entryType = formData.value.entryType;
    let res = await proxy.http.asyncPost(entryAPI.entryTreeList, queryForm);
    if (res.code === 0) {
      entryList.value = res.data;
      treeData.value = deepClone(entryList.value);
    } else {
      await uni.showToast({title: res.msg, icon: 'none'});
    }
  };

  /** 树组件 */
  const DaTreeRef = ref();
  const treeData = ref([]);
  const defaultCheckedKeysValue = ref([]); // 多选时默认值为数组
</script>

<style scoped lang="scss">
.s-all-check {
  .num{
    width: 180rpx;
  }
}
</style>
